package com.hsylient.javase.chapter09;

import com.hsylient.javase.common.enmu.Status;
import lombok.AllArgsConstructor;
import lombok.Data;
import org.junit.Test;

import java.util.Arrays;
import java.util.List;

public class TestReduce {

    private static final List<Employee> employees = Arrays.asList(
            new Employee(1L, "老xx", 73, 12.0, Status.BUSY),
            new Employee(1L, "李四", 23, 12.0, Status.FREE),
            new Employee(1L, "王五", 23, 3454.32, Status.VOCATION),
            new Employee(1L, "狗八", 53, 5454.32, Status.FREE),
            new Employee(1L, "琳九", 63, 6454.32, Status.BUSY),
            new Employee(1L, "赵六", 63, 4454.32, Status.FREE),
            new Employee(1L, "老十", 73, 7454.32, Status.VOCATION),
            new Employee(1L, "老zz", 73, 7454.32, Status.BUSY),
            new Employee(1L, "张三", 13, 1454.32, Status.VOCATION),
            new Employee(1L, "老yy", 73, 7454.32, Status.BUSY)
    );


    @Test
    public void testReduce() {
        Integer sumAge = employees.stream().map(Employee::getAge).reduce(Integer::sum).orElse(0);
        System.out.println(sumAge);
    }

    @Test
    public void testReduceFromZero() {
        Integer sumAge = employees.stream().map(Employee::getAge).reduce(0, Integer::sum);
        System.out.println(sumAge);
    }


    @Data
    @AllArgsConstructor
    private static class Employee {

        private Long id;

        private String name;

        private Integer age;

        private Double salary;

        private Status status;
    }

}
